<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>地址簿</title>
    <link rel="stylesheet" href="./css/address.css">
</head>

<body>
    <div class="wrap">
        <div class="searchWrap">
            <input type="text" class="search" placeholder="输入姓名手机号快速查询">
        </div>
        <div class="list"></div>
        <!-- 新增地址 -->
        <div class="bntWrap">
            <div class="shenhe_btn" onclick="add()">新增地址</div>
        </div>
    </div>
    <script src="./jquery/api.js" charset="utf-8"></script>
    <script src="./jquery/jquery.js"></script>
    <script>
        document.getElementsByClassName('wrap')[0].style.height = window.screen.height - 100 + "px"
        // 获取code
        function getQueryVariable(variable) {
            // 参数 window.location.search
            var query = decodeURI(window.location.search.substring(1));
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) {
                    return pair[1];
                }
            }
            return (false);
        }
        console.log(getQueryVariable('code'))
        function goBack(datas) {
            // 寄信息页面目前不需要code，所以跳转不需要code
            console.log(datas)
            window.location.href = "http://hesuan.city1000.cn/sao/saoma.html?dizhi=" + encodeURI(datas)
        }
        function edit(id) {
            console.log(id)
            window.location.href = "http://user.city1000.cn:9999/weixin/wechat/h5/redirectSomeWhere?url="
                + "http://hesuan.city1000.cn/sao/editAddress.html&data=" + id
        }
        $.ajax({
            url: api + "/getDiZhiBuByWeiXinCode",
            data: {
                weiXinCode: getQueryVariable('code')
            },
            success: function (res) {
                console.log('获取地址')
                if (res.code == 0) {
                    $('.list').html('')
                    if (res.list.length > 0) {
                        for (let i = 0; i < res.list.length; i++) {
                            $('.list').append(
                                `<div class="addressWrap">
                                    <div onclick='goBack(${res.list[i]})'>
                                        <div class="oneRow">
                                            <span>${res.list[i].name}</span>
                                            <span>${res.list[i].tel}</span>
                                        </div>
                                        <div class="twoRow">${res.list[i].gongsiname}${res.list[i].city}${res.list[i].quyu}</div>
                                    </div>
                                    <div class="edit">
                                        <div style="margin-right: 10px;">
                                            <img src="./image/edit.png" alt="" width="14">
                                            <span onclick='edit(${res.list[i].id})'>编辑</span>
                                        </div>
                                        <div>
                                            <img src="./image/del.png" alt="" width="14">
                                            <span onclick='delete(${res.list[i].id})'>删除</span>
                                        </div>
                                    </div>
                                 </div>`
                            )
                        }
                    } else {
                        $('.list').html(`<div class='noneText'>暂无数据</div>`)
                    }
                }
                console.log(res)
            },
            error: function () {
                console.log('网络繁忙')
            }
        })
        function add() {
            window.location.href = "http://user.city1000.cn:9999/weixin/wechat/h5/redirectSomeWhere?url="
                + "http://hesuan.city1000.cn/sao/addAddress.html&data=0"
        }

    </script>
</body>

</html>